package com.app.ui.receive;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.app.utiles.other.DLog;

import cn.jpush.android.api.JPushInterface;

/**
 * 自定义接收器
 * <p/>
 * 如果不定义这个 Receiver，则：
 * 1) 默认用户会打开主界面
 * 2) 接收不到自定义消息
 */
public class JGReceiver extends BroadcastReceiver {
    private static final String TAG = "JGReceiver极光";

    @Override
    public void onReceive(Context context, Intent intent) {
        final Bundle bundle = intent.getExtras();
        String action = intent.getAction();
        DLog.e(TAG, "推送类型：" + action);
        String jgId = JPushInterface.getRegistrationID(context);
        DLog.e(TAG, "推送id：" + jgId);
        if (JPushInterface.ACTION_REGISTRATION_ID.equals(intent.getAction())) {
            // 接收Registration Id
            //BaseApplication.DevicesManager(true);
            jgId = JPushInterface.getRegistrationID(context);
            DLog.e(TAG, "==推送id==：" + jgId);
            return;
        }
        if (bundle == null) {
            DLog.e(TAG, "bundle=null");
            return;
        }
        if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
            //接收到推送下来的自定义消息
            DLog.e(TAG, "接收到推送下来的自定义消息");
            return;
        }
        if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())) {
            //极光通知
            DLog.e(TAG, "极光通知");
            return;
        }
        if (JPushInterface.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
            //点击打开了通知
            DLog.e(TAG, "点击打开了通知");
            return;
        }

    }

}
